package com.kuang.controller;

import com.kuang.pojo.User;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/user")
public class UserController {

    @GetMapping("/t1")
    //前端的参数为username，后端使用name来接受，使用注解
    public String test1(@RequestParam("username") String name, Model model) {
        //接受前端参数
        System.out.println("接受到前端的参数为:" + name);
        //将返回的结果返回给前端
        model.addAttribute("msg", name);
        //跳转视图
        return "test";
    }

    @GetMapping("/t2")
    public String test2( User user) {
        System.out.println(user);
        return "test";
    }

    @GetMapping("/t3")
    public String test3(ModelMap modelMap){
        return "test";
    }
}
